package com.gpy.hospital.cms.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gpy.hospital.cms.dao.UrgentMapper;
import com.gpy.hospital.cms.pojo.LiuYan;
import com.gpy.hospital.cms.pojo.Urgent;
import com.gpy.hospital.cms.service.IUrgentService;
import com.gpy.hospital.common.ServerResponse;
import com.gpy.hospital.util.VerifyCodeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author
 * @Date 2020/6/1 20:28
 * @Desc
 **/
@Service
public class UrgentServiceImpl implements IUrgentService {
    @Autowired
    private UrgentMapper urgentMapper;
    @Override
    public String save(String phone) {
        Urgent urgent = new Urgent();
        urgent.setPhone(phone);
        // 未激活
        String verifyCode = VerifyCodeUtil.createVerifyCode();
        urgent.setCode(verifyCode);
        urgent.setStatus(1);
        urgentMapper.save(urgent);
        return verifyCode;
    }

    @Override
    public PageInfo<Urgent> getAll(Integer pageNum, Integer pageSize, String phone) {
        PageHelper.startPage(pageNum, pageSize);
        List<Urgent> urgents = urgentMapper.selectAllByPhone(phone);
        return new PageInfo<>(urgents);
    }

    @Override
    public ServerResponse update(Integer id) {
        int result = urgentMapper.update(id);
        if (result > 0) {
            return ServerResponse.createBySuccessMessage("成功！");
        }
        return ServerResponse.createByErrorMessage("失败！");
    }
}
